﻿using SharpPcap.LibPcap;
using SharpPcap;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace Core.Extension
{
    public static class PcapExtension
    {
        /// <summary>
        /// 获取LibPcapLiveDevice的mac地址(原生有提供mac地址，在wpf中无法调用)
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static PhysicalAddress? GetDeviceMacAddr(this ILiveDevice device)
        {
            if (device is LibPcapLiveDevice deviceImpl)
            {
                var address = deviceImpl.Addresses.FirstOrDefault(t => t.Addr.type == Sockaddr.AddressTypes.HARDWARE);
                if (address == null)
                {
                    return null;
                }
                else
                {
                    return address.Addr.hardwareAddress;
                }
            }
            else
            {
                return null;
            }
        }
    }
}
